package com.zsk.shop.controller.app;

import com.zsk.shop.common.annotion.NoPermission;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.enums.EnumLoginPlatform;
import com.zsk.shop.model.results.VerificationXYResults;
import com.zsk.shop.service.SmsService;
import com.zsk.shop.service.VerificationImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "短信相关")
@RequestMapping("/shop/smsCode")
public class VerificationCodeController {

    @Resource
    private SmsService smsService;
    @Resource
    private VerificationImageService verificationImageService;


    @NoPermission
    @GetMapping("/askSendSms.do")
    @ApiOperation("请求发送验证码")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "图形验证码编号", type = "String"),
            @ApiImplicitParam(name = "result", value = "图形验证码结果", type = "String"),
            @ApiImplicitParam(name = "type", value = "验证码类型 0注册，1登录，2绑定手机号，3修改密码"),
            @ApiImplicitParam(name = "decodeType", value = "type=2时才校验授权后类型1微信2钉钉3QQ"),
            @ApiImplicitParam(name = "phone", value = "手机号")})
    public BaseResponse askSendSms(String id, String result, Integer type, Integer decodeType, String phone) {
        return smsService.askSendSms(id, result, type, decodeType, phone, EnumLoginPlatform.IOS.getCode());
    }

    @NoPermission
    @GetMapping("/h5AskSendSms.do")
    @ApiOperation("H5请求发送验证码")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "图形验证码编号", type = "String"),
            @ApiImplicitParam(name = "result", value = "图形验证码结果", type = "String"),
            @ApiImplicitParam(name = "type", value = "验证码类型 0注册，1登录，2绑定手机号，3修改密码"),
            @ApiImplicitParam(name = "decodeType", value = "type=2时才校验授权后类型1微信2钉钉3QQ"),
            @ApiImplicitParam(name = "phone", value = "手机号")})
    public BaseResponse h5AskSendSms(String id, String result, Integer type, Integer decodeType, String phone) {
        return smsService.h5AskSendSms(id, result, type, decodeType, phone, EnumLoginPlatform.IOS.getCode());
    }

    @NoPermission
    @GetMapping("/askCheckSms.do")
    @ApiOperation("请求验证验证码")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "验证码类型 0注册，1登录，2绑定手机号，3修改密码"),
            @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "code", value = "验证码")})
    public BaseResponse askCheckSms(Integer type, String phone, String code) {
        return smsService.askCheckSms(type, phone, code);
    }

    @NoPermission
    @PostMapping("/getSlideCode.do")
    @ApiOperation("获取图形坐标")
    public BaseResponse<VerificationXYResults> getCodeImage() {
        return verificationImageService.randXYPoint();
    }

}
